{% extends "base.html" %}
{% import "_my_wtf_macros.html" as my_wtf_macros %}

{% block title %}万屏时代OPC--发布项目{% endblock %}

{% block head %}
    {{ super() }}
    <link href="https://cdn.bootcss.com/fancybox/3.1.20/jquery.fancybox.min.css"
          rel="stylesheet">
{% endblock %}

{% block panel_heading %}万屏时代OPC--发布项目{% endblock %}

{% block panel_body %}
    <form class="form form-inline form-group-sm" id="publish-demand-form"
          action="{{ url_for('op_bp.publish_demand', demand_id=demand.id) }}"
          method="post" role="form" >

        <div class="well well-sm">项目信息</div>
        {{ my_wtf_macros.form_field(form.id, div_col=6, label_col=5, field_col=7) }}
        {{ my_wtf_macros.form_field(form.uid, div_col=6, label_col=5, field_col=7) }}
        <div class="clearfix visible-xs-block visible-sm-block visible-md-block visible-lg-block"></div>
        {{ my_wtf_macros.form_field(form.user_nickname, div_col=6, label_col=5, field_col=7) }}
        {{ my_wtf_macros.form_field(form.user_mobile, div_col=6, label_col=5, field_col=7) }}
        <div class="clearfix visible-xs-block visible-sm-block visible-md-block visible-lg-block"></div>
        {{ my_wtf_macros.form_field(form.published_count, div_col=6, label_col=5, field_col=7) }}
        {% if form.published_count.data > 0 and demand.status in (10, 20, 30) %}
            {{ my_wtf_macros.form_field(form.only_notify, div_col=6, label_col=5, field_col=7) }}
        {% endif %}
        <div class="clearfix visible-xs-block visible-sm-block visible-md-block visible-lg-block"></div>
        {{ my_wtf_macros.form_field(form.current_demand_status, div_col=6, label_col=5, field_col=7) }}
        <div id="demand_status_div">
            {{ my_wtf_macros.form_field(form.demand_status, div_col=6, label_col=5, field_col=7) }}
        </div>
        <div class="clearfix visible-xs-block visible-sm-block visible-md-block visible-lg-block"></div>
        {{ my_wtf_macros.form_field(form.dispatch_count, div_col=6, label_col=5, field_col=7) }}
        <div class="clearfix visible-xs-block visible-sm-block visible-md-block visible-lg-block"></div>
        {{ my_wtf_macros.form_field(form.notice_way, div_col=6, label_col=5, field_col=7) }}
        {{ my_wtf_macros.form_field(form.notice_pay, div_col=1, label_col=1, field_col=7) }}
        {{ my_wtf_macros.form_field(form.contain_no_bind, div_col=2, label_col=1, field_col=7) }}

        <div class="clearfix visible-xs-block visible-sm-block visible-md-block visible-lg-block"></div>
        {{ my_wtf_macros.form_field(form.current_publish_remark, div_col=6, label_col=5, field_col=7, cols=60) }}
        <div class="clearfix visible-xs-block visible-sm-block visible-md-block visible-lg-block"></div>
        {{ my_wtf_macros.form_field(form.next_outbound, div_col=4, label_col=4, field_col=7) }}
        <div class="clearfix visible-xs-block visible-sm-block visible-md-block visible-lg-block"></div>

        <!--下次回访-->
        <div id="next_outbound_info">
            <div class="well well-sm">设置回访(仅发布项目时有效)</div>
            {{ my_wtf_macros.form_field(form.next_outbound_schedule_time, div_col=4, label_col=4, field_col=7) }}
            {{ my_wtf_macros.form_field(form.next_outbound_call_reason, div_col=4, label_col=4, field_col=7) }}
            <div class="clearfix visible-xs-block visible-sm-block visible-md-block visible-lg-block"></div>
        </div>
        <div class="clearfix visible-xs-block visible-sm-block visible-md-block visible-lg-block"></div>

        <!--计划外呼-->
        <div class="clearfix visible-xs-block visible-sm-block visible-md-block visible-lg-block"></div>
        <div id="outbound_record_info">
            <div class="well well-sm">计划外呼</div>

            <table id="schedule-outbound-records-table"
                   class="table table-bordered table-hover table-condensed table-striped">
                {% if schedule_outbound_records %}
                    <thead>
                    <tr>
                        <th>计划外呼时间</th>
                        <th>外呼原因</th>
                        <th>操作</th>
                    </tr>
                    </thead>
                    <tbody>
                    {% for r in schedule_outbound_records %}
                        <tr>
                            <td>{{ r.schedule_time_display }}</td>
                            <td>{{ r.call_reason_display }}</td>
                            <td>
                                <a
                                        class="btn btn-xs btn-primary"
                                        href="{{ url_for('outbound_bp.cancel_outbound', record_id=r.id) }}"
                                        name="cancel-outbound"
                                >取消外呼</a><br>
                            </td>
                        </tr>
                    {% endfor %}
                    </tbody>
                {% else %}
                    <tr>
                        <td>无</td>
                    </tr>
                {% endif %}
            </table>
        </div>
        <div class="clearfix visible-xs-block visible-sm-block visible-md-block visible-lg-block"></div>

        <div class="form-group col-xs-12">
            <button type="submit" name="submit_btn"
                    class="btn btn-success pull-right">确认发布
            </button>
        </div>

    </form>


{% endblock %}

{% block scripts %}
    {{ super() }}
    <script>
        $(document).ready(function () {
            // 若仅通知, 则不允许修改新项目状态
            $('#only_notify').change(function(){
                var flag = $(this).is(':checked');
                if (flag){
                    $('#demand_status_div').hide()
                }else{
                    $('#demand_status_div').show()
                }
            });

            // 设置回访联动
            var next_outbound_val = $('#next_outbound').is(':checked');
            if (next_outbound_val === true) {
                $('#next_outbound_info').show();
            } else {
                $('#next_outbound_info').hide();
            }
            $('#next_outbound').change(function () {
                var val = $(this).is(':checked');
                if (val === true) {
                    $('#next_outbound_info').show();
                } else {
                    $('#next_outbound_info').hide();
                }
            });

            $('#notice_way').change(function () {
                if ($(this).val() == '1' && $('#cate').val() == '4') {
                    $('#notice_pay').prop('checked', false)
                } else {
                    $('#notice_pay').prop('checked', true)
                }
            });

            $("#publish-demand-form").submit(function(){
                $('#publish-demand-form button[name="submit_btn"]').prop('disabled', true);
                return true;
            })
        });
    </script>

{% endblock %}
